﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ActiveReportsDemo.Viewers
{
    public partial class PrintViewer : DemoBaseUserControl
    {
        GrapeCity.ActiveReports.Viewer.Win.Viewer viewer;

        public PrintViewer()
        {
            InitializeComponent();

            ToolStripButton tsPrint1 = viewer1.Toolbar.MainBar.Items[2] as ToolStripButton;
            tsPrint1.Visible = false;

            ToolStripButton tsPrint = new ToolStripButton();
            tsPrint.ToolTipText = tsPrint1.ToolTipText;
            tsPrint.Text = tsPrint1.Text;
            tsPrint.Image = tsPrint1.Image;
            tsPrint.ImageAlign = tsPrint1.ImageAlign;
            tsPrint.ImageScaling = tsPrint1.ImageScaling;
            tsPrint.Click += new EventHandler(tsPrint_Click);
            viewer1.Toolbar.MainBar.Items.Insert(2, tsPrint);

            viewer = new GrapeCity.ActiveReports.Viewer.Win.Viewer();
            viewer.LoadCompleted += new GrapeCity.ActiveReports.Document.LoadCompletedEventHandler(viewer_LoadCompleted);
        }

        void viewer_LoadCompleted(object sender, EventArgs e)
        {
            viewer.Print(true);
        }

        public override void ShowReport(string name)
        {
            switch (name)
            {
                case "rptWayBill2":
                    CommonFunction.CreatePageReport("rptWayBill2", ThemePage, viewer1);
                    break;
                case "rptInvoice":
                    CommonFunction.CreatePageReport("rptInvoice", ThemePage, viewer1);
                    break;
                case "rptInvoice2":
                    CommonFunction.CreatePageReport("rptInvoice2", ThemePage, viewer1);
                    break;
                default:
                    break;
            }
        }

        void tsPrint_Click(object sender, EventArgs e)
        {
            GrapeCity.ActiveReports.PageReport page = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(string.Format(@"Reports\{0}.rdlx", CurrentReport)));
            page.Report.ReportParameters[0].DefaultValue.Values.Clear();
            page.Report.ReportParameters[0].DefaultValue.Values.Add("True");
            GrapeCity.ActiveReports.Document.PageDocument document = new GrapeCity.ActiveReports.Document.PageDocument(page);
            viewer.LoadDocument(document);                    
        }
    }
}
